#include"comm.hpp"

int main()
{
  shm client(CLIENT);
  
  //先开始写，写完给服务端发信息，然后等服务端通信
  int i = 0;
  while(i < 26)
  {
    int result1 = 1,result2 = 1;
    
    //拉长写入时间，方便观察
    sleep(2);

    //cin >> client.GetStart();

    char character = 'A' + i;
    client.GetStart()[i] = character;
    ++i;
    client.GetStart()[i] = '\0';

    //cout << "已写入信息" << endl;

    write(client.Get_client_namepipe(),&result1,sizeof(int)); 

    //cout << "已写入信号" << endl;

    //循环读取管道信息，直到达到条件
    while(true)
    {
      cout << "等待服务端读取完毕" << endl;
      read(client.Get_server_pipe(),&result2,sizeof(int));
      //cout << "已经读取到信号" << endl;
      if(result2 == 0)
      {
        break;
      }
    }
  }
  int result = -1;
  write(client.Get_client_namepipe(),&result,sizeof(int));
  cout << "客户端完成任务，进行退出" << endl;
  return 0;
}
